package com.acwing.partition11;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/3/6 22:34
 */
public class AC1070括号配对 {

    private static final int N = 110;
    private static String s;
    private static int[][] f = new int[N][N];
    private static int n;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        s = reader.readLine();
        n = s.length();
        for (int i = 0; i <= n; i++) f[i][i] = 1;
        for (int len = 2; len <= n; len++) {
            for (int i = 0; i + len - 1 < n; i++) {
                int j = i + len - 1;
                if (match(s.charAt(i), s.charAt(j))) {
                    f[i][j] = f[i + 1][j - 1];
                } else {
                    f[i][j] = Math.min(f[i + 1][j], f[i][j - 1]) + 1;
                }
                //如果 A 与 B 都是 GBE，那么 AB 是 GBE
                for (int k = i; k < j; k++) {
                    f[i][j] = Math.min(f[i][j], f[i][k] + f[k + 1][j]);
                }
            }
        }
        writer.write(f[0][n - 1] + "\n");
        writer.flush();
    }

    private static boolean match(char a, char b) {
        if (a == '[') return b == ']';
        if (a == '(') return b == ')';
        return false;
    }
}
